Mastering Bash by Giorgio Zarrelli
Author:Giorgio Zarrelli [Zarrelli, Giorgio]
Language: eng
Format: azw3, mobi, epub
Tags: COM088010 - COMPUTERS / System Administration / Linux & UNIX Administration, COM046030 - COMPUTERS / Operating Systems / UNIX, COM046070 - COMPUTERS / Operating Systems / Linux
Publisher: Packt Publishing
Published: 2017-06-21T04:00:00+00:00
Then there is something we never saw before:
| time=0.011048s;;;0.000000;10.000000
This is a pipe, followed by one or more labels, time in our example, and some values usually related to how the service is working. Whatever is written, it is not a Nagios concern, since it will not process this part of the output line. These values are there for third-party applications such as pnp4nagios or Nagios graph to process them and eventually draw out some performance graphics.
Nagios shows the performance data but does not really make use of it
We will see later how a graph for a service looks like, now let's remember one thing: the output of a plugin is usually one line long and even though you have a multiline output, it is always better to stick to a simple message.
Now, let's go back to the definition of the SSH service check, and let's see how to modify it to enable a different port check. This is the check_ssh command that we have already seen:
# 'check_ssh' command definition
define command{
command_name check_ssh
command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$'
}
To enable the definition of an arbitrary port check, we have to modify the command_line row so that it will accept the new -p parameter with an argument:
# 'check_ssh' command definition
define command{
command_name check_ssh
command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$' -p $ARG1$
}
What we did is simple: we just added a -p followed by $ARG1$. What is this new bit? In Nagios, you can pass whatever arguments you want to a script, and you refer to them using a positional variable. Think of $ARG1$ as $1 for a standard bash script; it identifies the first argument passed to the command line. Bear in mind that options like -p are not counted as arguments. So $ARG2$ will be the second positional argument, $ARG3$ the third, and so on. Do not forget the leading and trailing dollar signs. So, we modified the way Nagios can call the plugin, and now we can pass it an extra argument. What is left is to actually provide the extra argument to the script; this is done by modifying the service definition for ssh. We previously had this:
# check that ssh services are running
define service {
use generic-service
host_name localhost
service_description SSH
check_command check_ssh
}
This definition must be modified so that we can store and pass the port number to the command, so this is how we do it:
# check that ssh services are running
define service {
use generic-service
host_name localhost
service_description SSH
check_command check_ssh!1472
}
The exclamation mark (!) after the command name is a standard field separator and identifies the different positional arguments passed to the plugin. Let's make an example modifying the command_line of ssh to accept it:
-p 1472
-4
-P 2.0
-t 30
We must modify the command line to accept five parameters instead of one:
# 'check_ssh' command definition
define command{
command_name check_ssh
command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$' -p $ARG1$ -$ARG2$ -r $ARG3$ -P $ARG4$ -t $ARG5$
}
The modification is quite straightforward, we just wrote down all the switches and their arguments using the positional $ARGn$ variables. Now that the command line is ready to accept the new values, we must fill in the placeholders:
# check that
Download
Mastering Bash by Giorgio Zarrelli.mobi
Mastering Bash by Giorgio Zarrelli.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7773)
Filmora Efficient Editing by Alexander Zacharias(5875)
The Infinite Retina by Robert Scoble Irena Cronin(5347)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(4025)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3941)
Edit Like a Pro with iMovie by Regit(3474)
Linux Administration Best Practices by Scott Alan Miller(2864)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2840)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2529)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2445)
Docker on Windows by Stoneman Elton(2323)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2317)
Creative Projects for Rust Programmers by Carlo Milanesi(2292)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2115)
Hands-On Linux for Architects by Denis Salamanca(2056)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2012)
Computers For Seniors For Dummies by Nancy C. Muir(2009)
The Old New Thing by Raymond Chen(1943)
Linux Kernel Debugging by Kaiwan N Billimoria(1770)
